<script type="text/javascript">
    dojo.require("dijit.form.FilteringSelect");
    dojo.require("dojo.data.ItemFileReadStore");
</script>

<input class="hidden" id="{{field.uid}}" name="{{field.name}}" value="{{field.value.id|escape:'html'}}">

<script type="text/javascript">
    dojo.addOnLoad(function() {
        var m2o_store = new dojo.data.ItemFileReadStore({ url: "{{baseurl}}system/search/relation/?class={{field.class_name}}&field={{field.name}}&dojo=true" });
        var filteringSelect = new dijit.form.FilteringSelect({
            id: "{{field.uid}}",
            name: "{{field.name}}",
            value: "{{field.value.id|escape:'js'}}",
            store: m2o_store,
            searchAttr: "name",
        },
        "{{field.uid}}");
    });
</script>